package com.epam.lissina.controller;

import java.util.List;
import java.util.ResourceBundle;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import com.epam.lissina.entity.Sentence;
import com.epam.lissina.entity.Text;
import com.epam.lissina.task.PersonalTask;
import com.epam.lissina.utils.ActionWithFile;

public class Runner {

	public static final Logger logger = Logger.getLogger(Runner.class);
	public static ResourceBundle rb;

	public static void main(String[] args) {
		PropertyConfigurator.configure("src/properties/log4j.properties");
		rb = ResourceBundle.getBundle("properties/property");

		logger.info("Start reading text from file");
		String str = ActionWithFile.read(rb.getString("FileInput"));
		if (str.isEmpty()) {
			logger.info("File is empty or not found");
			return;
		}
		Text text = new Text(str);
		logger.info("End of reading text from file");

		logger.info("Start write text to a file");
		ActionWithFile.write(rb.getString("FileOutput"), text.toString());
		logger.info("End of reading text from file");

		logger.info("Deduce all the sentences specified text in ascending order number of words in each of them");
		List<Sentence> sentences = PersonalTask
				.sentencesAscendingNmberWords(text);
		for (Sentence sentence : sentences) {
			ActionWithFile.write(rb.getString("FileWithTask"),
					sentences.toString());
			logger.info(sentence.toString());
		}
	}
}